﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行基本数据 - 学生名单下载");
		
		propAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
	
		grade = event.getArg("grade");
		
		termDateStart = year( now() );
		
		/* 当前在校生判断 grade + schooling_length > ? */
		if ( month( now() ) < 9 ) {
			termDateStart = termDateStart - 1;
		}

		/*年级*/
		sql = "SELECT 
					t_class.grade, count(*) countStu 
				FROM 
					t_student 
					INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
				WHERE 
					(t_class.grade + t_subject.schooling_length) > :yearNow 
				GROUP BY 
					t_class.grade 
				ORDER BY 
					t_class.grade DESC ";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
		queryObj.addParam( name="yearNow", value=termDateStart, cfsqltype="cf_sql_decimal", scale=1  );
		
		rs_grade = queryObj.execute( sql=sql ).getResult();
		
		/* 学院 */
		sql = "SELECT 
					t_institute.institute_id, t_institute.institute_name, count(*) countStu 
				FROM 
					t_student 
					INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id  
					INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
				WHERE 
					(t_class.grade + t_subject.schooling_length) > :yearNow 
				GROUP BY 
					t_institute.institute_id, t_institute.institute_name 
				ORDER BY 
					t_institute.institute_name ";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
		queryObj.addParam( name="yearNow", value=termDateStart, cfsqltype="cf_sql_decimal", scale=1  );
		
		rs_ins = queryObj.execute( sql=sql ).getResult();
	
		currentTab = event.getArg("TabID", "labInstitute");
		
		if( len(grade) ){
			
			sql = "SELECT 
						t_institute.institute_id, t_institute.institute_name, count(*) countStu 
					FROM 
						t_student 
						INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
						INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id  
						INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
					WHERE 
						t_class.grade = :grade 
						AND 
						(t_class.grade + t_subject.schooling_length) > :yearNow 
					GROUP BY 
						t_institute.institute_id, t_institute.institute_name 
					ORDER BY 
						t_institute.institute_name ";
					
			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="yearNow", value=termDateStart, cfsqltype="cf_sql_decimal", scale=1  );
			
			rs_insGrade = queryObj.execute( sql=sql ).getResult();
		
			currentTab = event.getArg("TabID", "labGrade" & grade);
		}
			
		passArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">学籍信息管理</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 link"></i>学生名单下载
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="administration">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labInstitute">class="active"</cfif> id="labInstitute" tabTarget="Institute">按学院下载</span>
                        <span <cfif currentTab eq "labGrade">class="active"</cfif> id="labGrade" tabTarget="Grade">按年级下载</span>
                        <cfif len(grade)>
							<span <cfif currentTab eq "labGrade" & grade>class="active"</cfif> id="labGrade<cfoutput>#grade#</cfoutput>" tabTarget="Grade<cfoutput>#grade#</cfoutput>"><cfoutput>#grade#</cfoutput>级</span>
						</cfif>
					</div>
				</div>
                
                <script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>				
				</script>
			
			</div>
			
			<div id="Institute" class="tabContent">
				
				<div class="noticeBlock">
                	<div class="operation">
                        <a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentBySchoolDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载全校学生名单</span></a>
                    </div>
                            
					<h3>二级院(系)</h3>
					<p><span class="img icon16x16 message"></span>这里列出所有承担教学任务和有学生的校内学院</p>
					<hr/>
				</div>
				
				<div class="clearfix">
					<div class="UICardTable">
                        <cfloop query="rs_ins"  >
							<cfset structInsert(passArgs, "InsID", rs_ins.institute_id, true) />
                            <cfset structInsert(passArgs, "DateStart", termDateStart, true) />
							<dl>
								<dt>
									<a href="<cfoutput>#buildURL('studentByInstituteDownloadExcel', passArgs)#</cfoutput>">
									<b class="school"><!--imgholder--></b>
									<dd>
										<h3><cfoutput>#rs_ins.institute_name#</cfoutput></h3>
										<div>共有学生 <cfoutput>#rs_ins.countStu#</cfoutput> 名</div>
									</dd>
									</a>
								</dt>
							</dl>
						</cfloop>
					</div>
				</div>
                
             </div>
             
             
             <div id="Grade" class="tabContent">
				
				<div class="noticeBlock">
                	<div class="operation">
                        <a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentBySchoolDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载全校学生名单</span></a>
                    </div>
                            
					<h3>在校学生年级</h3>
					<p><span class="img icon16x16 message"></span>这里列出所有承担教学任务和有学生的年级</p>
					<hr/>
				</div>
				
				<div class="clearfix">
					<div class="UICardTable">
                        <cfloop query="rs_grade"  >
							<cfset structInsert(passArgs, "Grade", rs_grade.grade, true) />
                            <cfset structInsert(passArgs, "DateStart", termDateStart, true) />
							<dl>
								<dt>
									<a href="<cfoutput>#buildURL('studentDocument', passArgs)#</cfoutput>">
									<b class="grade"><!--imgholder--></b>
									<dd>
										<h3><cfoutput>#rs_grade.grade#级</cfoutput></h3>
										<div>共有学生 <cfoutput>#rs_grade.countStu#</cfoutput> 名</div>
									</dd>
									</a>
								</dt>
							</dl>
						</cfloop>
					</div>
				</div>
          
             </div>
             
             <cfif len(grade)>
             
                 <div id="Grade<cfoutput>#grade#</cfoutput>" class="tabContent">
                    
                    <cfset structInsert(passArgs, "Grade", grade, true) />
                    
                    <div class="noticeBlock">
                        <div class="operation">
                            <a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentByGradeDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载<cfoutput>#grade#</cfoutput>级所有学生名单</span></a>
                        </div>
                                
                        <h3>二级院(系)</h3>
                        <p><span class="img icon16x16 message"></span>这里列出<em><cfoutput>#grade#</cfoutput></em>级所有承担教学任务和有学生的校内学院</p>
                        <hr/>
                    </div>
                    
                    <div class="clearfix">
                        <div class="UICardTable">
                            <cfloop query="rs_insGrade"  >
                                <cfset structInsert(passArgs, "InsID", rs_insGrade.institute_id, true) />
                                <cfset structInsert(passArgs, "DateStart", termDateStart, true) />
                                <dl>
                                    <dt>
                                        <a href="<cfoutput>#buildURL('studentByInstituteDownloadExcel', passArgs)#</cfoutput>">
                                        <b class="school"><!--imgholder--></b>
                                        <dd>
                                            <h3><cfoutput>#rs_insGrade.institute_name#</cfoutput></h3>
                                            <div>共有学生 <cfoutput>#rs_insGrade.countStu#</cfoutput> 名</div>
                                        </dd>
                                        </a>
                                    </dt>
                                </dl>
                            </cfloop>
                        </div>
                    </div>
                    
                 </div>	
                 
        	</cfif>

		</li>
	</ul>
</div>

